package com.marvels.approve.manager.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.approve.manager.dto.CaseNodeRoleDTO;
import com.marvels.approve.manager.service.ICaseNodeRoleService;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;

/**流程角色服务
 * @author 何杰
 * 2018年4月10日
 */
@RestController
@RequestMapping("approve/case_node_role/service")
public class CaseNodeRoleController {
	@Autowired
	private ICaseNodeRoleService caseNodeRoleService;
	
	@RequestMapping("list")
	@ResponseBody
	public MarvelsResultDTO queryCaseNodeRole(@RequestBody(required=false) CaseNodeRoleDTO caseNodeRoleDTO){
		try {
			List datas = caseNodeRoleService.findCaseNodeRoles(caseNodeRoleDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), datas);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().warn("marvels_error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**新增或者更新
	 * @author 何杰
	 * 2018年4月10日
	 * @return
	 */
	@RequestMapping("merge")
	@ResponseBody
	public MarvelsResultDTO saveOrUpdateCaseNodeRole(@RequestBody(required=false) CaseNodeRoleDTO caseNodeRole ){
		try {
			caseNodeRole = this.caseNodeRoleService.saveCaseNodeRole(caseNodeRole);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), caseNodeRole);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().warn("marvels_error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getid")
	@ResponseBody
	public MarvelsResultDTO getCaseNodeRole(@RequestBody(required=false) CaseNodeRoleDTO caseNodeRole ){
		try {
			caseNodeRole = this.caseNodeRoleService.findCaseNodeRole(caseNodeRole.getId());
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), caseNodeRole);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().warn("marvels_error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	 
}
